package com.ming.demo.easyiot;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/5.
 */

public class StateUtil {
    public static final int CONNECT = 0;
    public static final int QUERY101 = 1;
    public static final int GPS = 2;
    public static final int PING = 3;
    public static final int APPLICATION = 4;
    public static final int BAND = 5;
    public static final int IMEI = 6;
    public static final int IMSI = 7;
    public static final int CFUN = 8;
    public static final int CGAT = 9;
    public static final int APN = 10;
    public static final int IPADDRESS = 11;
    public static final int QUERY102 = 12;
    public static final int CYCLE = 13;

    int position = 0;
    MainActivity activity;
    List<String> commandList = new ArrayList<>();
    List stateList = new ArrayList<>();

    public StateUtil(MainActivity activity) {
        this.activity = activity;
    }

    public void AddList(String command, int state) {
        switch (state) {
            case CONNECT:
                if (activity.UEType == -1) {
                    commandList.add(command);
                    stateList.add(state);
                }
                break;
            case QUERY101:
                commandList.add(command);
                stateList.add(state);
                break;
            case GPS:
                commandList.add(command);
                stateList.add(state);
                break;
            case PING:
                commandList.add(command);
                stateList.add(state);
                break;
            case APPLICATION:
                if (activity.ModelVersion.equals("")) {
                    commandList.add(command);
                    stateList.add(state);
                }
                break;
            case BAND:
                commandList.add(command);
                stateList.add(state);
                break;
            case IMEI:
                if (activity.IMEI.equals("")) {
                    commandList.add(command);
                    stateList.add(state);
                }
                break;
            case IMSI:
                if (activity.IMSI.equals("")) {
                    commandList.add(command);
                    stateList.add(state);
                }
                break;
            case CFUN:
                commandList.add(command);
                stateList.add(state);
                break;
            case CGAT:
                commandList.add(command);
                stateList.add(state);
                break;
            case APN:
                commandList.add(command);
                stateList.add(state);
                break;
            case IPADDRESS:
                commandList.add(command);
                stateList.add(state);
                break;
            case QUERY102:
                commandList.add(command);
                stateList.add(state);
                break;
        }
    }

    public void resetList() {
        commandList = new ArrayList<>();
        stateList = new ArrayList<>();
        position = 0;
    }

    public int getNextState() {
        if (position == stateList.size()) {
            return -1;
        }
        int state = Integer.parseInt(stateList.get(position).toString());
        return state;
    }

    public String getNextCommand() {
        String command = commandList.get(position);
        position++;
        return command;
    }

    public void setCommand() {
        resetList();
        if (activity.UEType == 101) {
            set101Command();
        } else if (activity.UEType == 102) {
            set102Command();
        } else {
            AddList(activity.Connect, CONNECT);
        }
    }

    public void set101Command() {
        resetList();
        AddList(activity.Query, QUERY101);
        AddList(activity.GPS, GPS);
    }

    public void set102Command() {
        resetList();
        AddList(activity.GetApn, APN);
        AddList(activity.GetIp, IPADDRESS);
        AddList(activity.GetPlaceInfo, QUERY102);
    }
}
